<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 7. Built-in Functions</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="smarty.for.designers.html" title="Part II. Smarty For Template Designers">
<link rel="prev" href="language.combining.modifiers.html" title="Chapter 6. Combining Modifiers">
<link rel="next" href="language.function.append.html" title="{append}">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 7. Built-in Functions</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="language.combining.modifiers.html">Prev</a> </td>
<th width="60%" align="center">Part II. Smarty For Template Designers</th>
<td width="20%" align="right"> <a accesskey="n" href="language.function.append.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter" title="Chapter 7. Built-in Functions">
<div class="titlepage"><div><div><h2 class="title">
<a name="language.builtin.functions"></a>Chapter 7. Built-in Functions</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="sect1"><a href="language.builtin.functions.html#language.function.shortform.assign">{$var=...}</a></span></dt>
<dt><span class="sect1"><a href="language.function.append.html">{append}</a></span></dt>
<dt><span class="sect1"><a href="language.function.assign.html">{assign}</a></span></dt>
<dt><span class="sect1"><a href="language.function.block.html">{block}</a></span></dt>
<dt><span class="sect1"><a href="language.function.call.html">{call}</a></span></dt>
<dt><span class="sect1"><a href="language.function.capture.html">{capture}</a></span></dt>
<dt><span class="sect1"><a href="language.function.config.load.html">{config_load}</a></span></dt>
<dt><span class="sect1"><a href="language.function.debug.html">{debug}</a></span></dt>
<dt><span class="sect1"><a href="language.function.extends.html">{extends}</a></span></dt>
<dt><span class="sect1"><a href="language.function.for.html">{for}</a></span></dt>
<dt><span class="sect1"><a href="language.function.foreach.html">{foreach},{foreachelse}</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.property.index">@index</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.property.iteration">@iteration</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.property.first">@first</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.property.last">@last</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.property.show">@show</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.property.total">@total</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.construct.break">{break}</a></span></dt>
<dt><span class="sect2"><a href="language.function.foreach.html#foreach.construct.continue">{continue}</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="language.function.function.html">{function}</a></span></dt>
<dt><span class="sect1"><a href="language.function.if.html">{if},{elseif},{else}</a></span></dt>
<dt><span class="sect1"><a href="language.function.include.html">{include}</a></span></dt>
<dt><span class="sect1"><a href="language.function.include.php.html">{include_php}</a></span></dt>
<dt><span class="sect1"><a href="language.function.insert.html">{insert}</a></span></dt>
<dt><span class="sect1"><a href="language.function.ldelim.html">{ldelim},{rdelim}</a></span></dt>
<dt><span class="sect1"><a href="language.function.literal.html">{literal}</a></span></dt>
<dt><span class="sect1"><a href="language.function.nocache.html">{nocache}</a></span></dt>
<dt><span class="sect1"><a href="language.function.php.html">{php}</a></span></dt>
<dt><span class="sect1"><a href="language.function.section.html">{section},{sectionelse}</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="language.function.section.html#section.property.index">.index</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.index.prev">.index_prev</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.index.next">.index_next</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.iteration">.iteration</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.first">.first</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.last">.last</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.rownum">.rownum</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.loop">.loop</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.show">.show</a></span></dt>
<dt><span class="sect2"><a href="language.function.section.html#section.property.total">.total</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="language.function.setfilter.html">{setfilter}</a></span></dt>
<dt><span class="sect1"><a href="language.function.strip.html">{strip}</a></span></dt>
<dt><span class="sect1"><a href="language.function.while.html">{while}</a></span></dt>
</dl>
</div>
<p>
  Smarty comes with several built-in functions. These built-in functions
  are the integral part of the smarty template engine. They are compiled
  into corresponding inline PHP code for maximum performance.
  </p>
<p>
  You cannot create your own
  <a class="link" href="language.custom.functions.html" title="Chapter 8. Custom Functions">custom functions</a>
  with the same name; and you  should  not need to
  modify the built-in functions.
  </p>
<p>
 A few of these functions have an <em class="parameter"><code>assign</code></em>
 attribute which collects the result the function to a named template
 variable instead of being output;
 much like the <a class="link" href="language.function.assign.html" title="{assign}">
 <code class="varname">{assign}</code></a> function.
 </p>
<div class="sect1" title="{$var=...}">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="language.function.shortform.assign"></a>{$var=...}</h2></div></div></div>
<p>
  This is a short-hand version of the {assign} function. You can
  assign values directly to the template, or assign values to array elements too.
 </p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
   Assignment of variables in-template is essentially placing application logic into the presentation that may be better handled in PHP. Use at your own discretion.
 </p>
</div>
<p>
  The following attributes can be added to the tag:
 </p>
<p><span class="bold"><strong>Attributes:</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Attribute Name</th>
<th align="center">Shorthand</th>
<th align="center">Type</th>
<th align="center">Required</th>
<th align="center">Default</th>
<th>Description</th>
</tr></thead>
<tbody><tr>
<td align="center">scope</td>
<td align="center">n/a</td>
<td align="center">string</td>
<td align="center">No</td>
<td align="center"><span class="emphasis"><em>n/a</em></span></td>
<td>The scope of the assigned variable: 'parent','root' or 'global'</td>
</tr></tbody>
</table></div>
<p><span class="bold"><strong>Option Flags:</strong></span></p>
<div class="informaltable"><table border="1">
<colgroup>
<col align="center">
<col>
</colgroup>
<thead><tr>
<th align="center">Name</th>
<th>Description</th>
</tr></thead>
<tbody><tr>
<td align="center">nocache</td>
<td>Assigns the variable with the 'nocache' attribute</td>
</tr></tbody>
</table></div>
<div class="example">
<a name="id364192"></a><p class="title"><b>Example 7.1. Simple assignment</b></p>
<div class="example-contents">
<pre class="programlisting">

{$name='Bob'}

The value of $name is {$name}.

  </pre>
<p>
   The above example will output:
  </p>
<pre class="screen">

The value of $name is Bob.

  </pre>
</div>
</div>
<br class="example-break"><div class="example">
<a name="id364217"></a><p class="title"><b>Example 7.2. Assignment with math</b></p>
<div class="example-contents"><pre class="programlisting">

{$running_total=$running_total+$some_array[row].some_value}

  </pre></div>
</div>
<br class="example-break"><div class="example">
<a name="id364230"></a><p class="title"><b>Example 7.3. Assignment of an array element</b></p>
<div class="example-contents"><pre class="programlisting">

{$user.name="Bob"}

  </pre></div>
</div>
<br class="example-break"><div class="example">
<a name="id364243"></a><p class="title"><b>Example 7.4. Assignment of an multidimensional array element</b></p>
<div class="example-contents"><pre class="programlisting">

{$user.name.first="Bob"}

  </pre></div>
</div>
<br class="example-break"><div class="example">
<a name="id364256"></a><p class="title"><b>Example 7.5. Appending an array</b></p>
<div class="example-contents"><pre class="programlisting">

{$users[]="Bob"}

  </pre></div>
</div>
<br class="example-break"><div class="example">
<a name="id364269"></a><p class="title"><b>Example 7.6. Assigment in the scope of calling template</b></p>
<div class="example-contents">
<p>Variables assigned in the included template will be seen in the including template.</p>
<pre class="programlisting">

{include file="sub_template.tpl"}
...
{* display variable assigned in sub_template *}
{$foo}&lt;br&gt;
...

  </pre>
<p>The template above includes the example <code class="filename">sub_template.tpl</code> below</p>
<pre class="programlisting">

...
{* foo will be known also in the including template *}
{$foo="something" scope=parent}
{* bar is assigned only local in the including template *}
{$bar="value"}
...

</pre>
</div>
</div>
<br class="example-break"><p>
  See also <a class="link" href="language.function.assign.html" title="{assign}"><code class="varname">{assign}</code></a>
  and
  <a class="link" href="language.function.append.html" title="{append}"><code class="varname">{append}</code></a>
 </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="language.combining.modifiers.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="smarty.for.designers.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="language.function.append.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Chapter 6. Combining Modifiers </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> {append}</td>
</tr>
</table>
</div>
</body>
</html>
